#include "queue.h"
#include <stdlib.h>
#include <stdio.h>

DataNode* createDataNode(int data) {
	DataNode* dataNode = (DataNode*) malloc(sizeof(DataNode));
	dataNode->data = data;
	dataNode->next = NULL;
	return dataNode;
}

void deleteDataNode(DataNode* dataNode) {
	free(dataNode);
}

DataNode* addToFront(DataNode* queue, DataNode* dataNode, int& currentCount) {
	if (currentCount < MAX_SIZE) {
		dataNode->next = queue;
		currentCount++;
	} else {
		removeLast(queue);
		dataNode->next = queue;
	}
	return dataNode;
}

void removeLast(DataNode* queue) {
	DataNode* start = queue;
	while(queue->next != NULL) {
		if (queue->next->next == NULL) {
			deleteDataNode(queue->next);
			queue->next = NULL;
			break;
		}
		queue = queue->next;
	}
	queue = start;
}

void printQueue(DataNode* queue) {
	DataNode* start = queue;
	while(queue != NULL) {
		printf("%d ", queue->data);
		queue = queue->next;
	}
	printf("\n");
	queue = start;
}

void deleteQueue(DataNode* queue) {
	if (queue->next == NULL) {
		deleteDataNode(queue);
	} else {
		deleteQueue(queue->next);
	}
}

int getSum(DataNode* queue) {
	// TODO

	return 0;

}

float getAverage(DataNode* queue) {
	// TODO

	return 0.0f;
}

float getStandardDeviation(DataNode* queue) {
	// TODO

	return 0.0f;
}
